<?php
class CatsModel extends RelationModel {
	
	public $_link = array(
			'Post_cat'=> array(
			
					'mapping_type'=>HAS_MANY,
			
					'class_name'=>'Post_cat',
			
					'mapping_name'=>'in_post',
					
					'foreign_key'=>'cat_id',
					//post_user
					'parent_key'=>'cat_id'),
			
			
			'Father'=> array(
						
					'mapping_type'=>HAS_ONE,
						
					'class_name'=>'Cats',
						
					'mapping_name'=>'father',
					
					'mapping_key'=>'cat_father',
					
					'foreign_key'=>'cat_father',
					
					'parent_key'=>'cat_id'),
	);
	

    public function category() {
      import("@.ORG.Category");

       $Cat = new Category('Cats',array('cat_id', 'cat_father', 'cat_name', 'cat_slug'));//, array('cid', 'pid', 'name', 'fullname')
            
       return $Cat->getList();              
        
           
    }
	
    public function del($cat_id,$child=false) {
    	import("@.ORG.Category");
    
    	$Cat = new Category('Cats',array('cat_id', 'cat_father', 'cat_name', 'cat_slug'));//, array('cid', 'pid', 'name', 'fullname')
    
    	if ($child) {
    		D('Cats')->where(array('cat_father'=>$cat_id))->relation(true)->delete();
    	}else {
    		D('Cats')->where(array('cat_father'=>$cat_id))->setField('cat_father',0);
    	}
    	
    	
    	return $Cat->del($cat_id);
    
    	 
    }
    
    
	
	
	
	
}